<template>
  <el-card shadow="never" class="aui-card--fill">
    <el-radio-group v-for="type in m_ltPageType" :key="type.value" style="float: right" v-model="m_nPageType" @change="switchType">
      <el-radio-button :label="type.value">{{type.name}}</el-radio-button>
    </el-radio-group>
    <search-bar ref="SearchBar" :model="model" :fields="searchFields[m_nPageType]"  @search="search"></search-bar>
    <div class="mod-stock__mortalitybreed}">
      <el-form :inline="true" :model="dataForm" @keyup.enter.native="getDataList()">
        <el-form-item>
          <el-button type="info" @click="exportHandle()">{{ $t('export') }}</el-button>
        </el-form-item>
        <el-form-item>
          <el-button type="primary" @click="addOrUpdateHandle()">{{ $t('add') }}</el-button>
        </el-form-item>
        <el-form-item>
          <el-button v-if="$hasPermission('stock:mortalitybreed:delete')" type="danger" @click="deleteHandle()">{{ $t('deleteBatch') }}</el-button>
        </el-form-item>
      </el-form>
      <el-table v-loading="dataListLoading" :data="dataList" border @selection-change="dataListSelectionChangeHandle" style="width: 100%;">
        <el-table-column type="selection" header-align="center" align="center" width="50"></el-table-column>
        <el-table-column v-for="field in m_mapFields[m_nPageType]" :key="field.prop" :prop="field.prop" :fixed="field.fixed" :label="field.label" header-align="center" align="center"></el-table-column>
        <el-table-column :label="$t('handle')" fixed="right" header-align="center" align="center" width="150">
          <template slot-scope="scope">
            <el-button v-if="$hasPermission('stock:mortalitybreed:update')" type="text" size="small" @click="addOrUpdateHandle(scope.row.id)">{{ $t('update') }}</el-button>
            <el-button v-if="$hasPermission('stock:mortalitybreed:delete')" type="text" size="small" @click="deleteHandle(scope.row.id)">{{ $t('delete') }}</el-button>
          </template>
        </el-table-column>
      </el-table>
      <el-pagination
        :current-page="page"
        :page-sizes="[10, 20, 50, 100]"
        :page-size="limit"
        :total="total"
        layout="total, sizes, prev, pager, next, jumper"
        @size-change="pageSizeChangeHandle"
        @current-change="pageCurrentChangeHandle">
      </el-pagination>
      <!-- 弹窗, 新增 / 修改 -->
      <!--<add-or-update v-if="addOrUpdateVisible" ref="addOrUpdate" @refreshDataList="getDataList"></add-or-update>-->
      <add-model v-if="addOrUpdateVisible" ref="addOrUpdate" @refreshDataList="getDataList" :model="model" :fields="m_mapFields[m_nPageType]"></add-model>
    </div>
  </el-card>
</template>

<script>
import mixinViewModule from '@/mixins/view-module'
import AddOrUpdate from './mortalitybreed-add-or-update'
import AddModal from './pig/add-or-update'
import SearchBar from './search-bar'
/* eslint-disable */
export default {
  mixins: [mixinViewModule],
  data () {
    return {
      model: 'mortalitybreed',
      m_ltPageType: [{ name: '种猪', value: 0 }, { name: '生长猪', value: 1 }],
      m_nPageType: 0,
      m_mapFields: {
        0: [{ prop: 'houseId', label: '所在猪舍', fixed: 'left', readonly: true, search: true }, { prop: 'earmark', label: '耳号', fixed: 'left', required: true, search: true }, { prop: 'mortalityDate', label: '淘汰时间', required: true, search: true }, { prop: 'weight', label: '重量', type: 'number' }, { prop: 'reason', label: '原因', required: true, search: true }, { prop: 'operator', label: '饲养员' }, { prop: 'remark', label: '备注' }, { prop: 'creator', label: '创建者', readonly: true }, { prop: 'createDate', label: '创建时间', readonly: true }],
        1: [{ prop: 'houseId', label: '所在猪舍', fixed: 'left', required: true, search: true }, { prop: 'mortalityDate', label: '淘汰时间', fixed: 'left', required: true, search: true }, { prop: 'gridId', label: '栏位' }, { prop: 'mounts', label: '头数', fixed: 'left', type: 'number', required: true }, { prop: 'age', label: '日龄', type: 'number' }, { prop: 'weight', label: '重量', type: 'number' }, { prop: 'reason', label: '原因', required: true }, { prop: 'operator', label: '鉴定人' }, { prop: 'remark', label: '备注' }, { prop: 'creator', label: '创建者', readonly: true }, { prop: 'createDate', label: '创建时间', readonly: true }]
      },
      searchFields: {
        0: [{ prop: 'houseId', label: '所在猪舍', fixed: 'left', readonly: true, search: true }, { prop: 'earmark', label: '耳号', fixed: 'left', required: true, search: true }, { prop: 'mortalityDate', label: '淘汰时间', required: true, search: true }, { prop: 'mortalityDateStart', label: '淘汰时间', required: true, search: false }, { prop: 'mortalityDateEnd', label: '淘汰时间', required: true, search: false }, { prop: 'reason', label: '原因', required: true, search: true }],
        1: [{ prop: 'houseId', label: '所在猪舍', fixed: 'left', required: true, search: true }, { prop: 'mortalityDate', label: '淘汰时间', fixed: 'left', required: true, search: true }, { prop: 'mortalityDateStart', label: '淘汰时间', required: true, search: false }, { prop: 'mortalityDateEnd', label: '淘汰时间', required: true, search: false }]
      },
      mixinViewModuleOptions: {
        getDataListURL: '/stock/mortalitybreed/page',
        getDataListIsPage: true,
        exportURL: '/stock/mortalitybreed/export',
        deleteURL: '/stock/mortalitybreed',
        deleteIsBatch: true
      },
      dataForm: {
        id: ''
      }
    }
  },
  components: {
    AddOrUpdate,
    'add-model': AddModal,
    SearchBar
  },
  methods: {
    switchType () {
      if (this.m_nPageType === 0) {
        this.model = 'mortalitybreed'
        this.getDataListURL = `/stock/${this.model}/page`
        this.exportURL = `/stock/${this.model}/export`
      } else {
        this.model = 'mortalitygrowth'
        this.getDataListURL = `/stock/${this.model}/page`
        this.exportURL = `/stock/${this.model}/export`
      }
      this.query()
    }
  }
}
</script>
